package j03close;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class J1 {
    public static void main(String[] args) {
        FileInputStream f = null;
        try {
            f = new FileInputStream("_1218/src/j03close/a.txt");
            System.out.println("f.read() = " + f.read());
//            f.close();
        } catch (FileNotFoundException e) {
//            try {
//                f.close();
//            } catch (IOException ex) {
//                throw new RuntimeException(ex);
//            }
            throw new RuntimeException(e);
        } catch (IOException e) {
//            try {
//                f.close();
//            } catch (IOException ex) {
//                throw new RuntimeException(ex);
//            }
            throw new RuntimeException(e);
        } finally {
            try {
                f.close();
            } catch (IOException ex) {
                throw new RuntimeException(ex);
            }
        }

    }
}

class C1 implements AutoCloseable{
    @Override
    public void close() throws Exception {
        System.out.println("c1 closed");
    }
}

class J2auto{
    public static void main(String[] args) {
        try (
                FileInputStream f = new FileInputStream("_1218/src/j03close/a.txt");
                C1 c1 = new C1()
        ) {
            System.out.println("f.read() = " + f.read());


        }catch (Exception e){

        }
    }
}